package com.qx;

import com.qx.dao.usersMapper;
import com.qx.pojo.user;
import com.qx.units.Mybatis;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.List;

public class testad {

    @Test
    public void  test() {
        //1、获取sqlsession 对象
        SqlSession getsession = Mybatis.getsession();
        //2、执行sql
        usersMapper mapper = getsession.getMapper(usersMapper.class);
        List<user> getusers = mapper.getusers();
        for (user getuser : getusers) {
            System.out.println(getuser);
        }
        getsession.close();
    }
    @Test
    public void getnamebyid(){
        SqlSession getsession = Mybatis.getsession();
        usersMapper mapper = getsession.getMapper(usersMapper.class);
        user user = mapper.getnameById(1);
        System.out.println(user);
        getsession.close();
    }

    @Test
    public void insertdata(){
        SqlSession getsession = Mybatis.getsession();
        usersMapper mapper = getsession.getMapper(usersMapper.class);
        int xiaolong = mapper.insertdata(new user(6, "xi1aolong", "123123"));
        System.out.println(xiaolong);
        getsession.commit();
        getsession.close();
    }
}
